package cn.wp.ewallet.upms.dao.impl;

import cn.wp.common.core.dao.JdbcSupportTemplate;
import cn.wp.common.core.dao.SqlString;
import cn.wp.ewallet.upms.dao.OrganizationInfoDao;
import cn.wp.ewallet.upms.model.entity.OrganizationInfoDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName OrganizationInfoDaoImpl
 * @Author ruixule
 * @Description TODO
 * @Date 2019/12/27 10:42
 */
@Repository
public class OrganizationInfoDaoImpl implements OrganizationInfoDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;

    /**
     * 通过员工id 查询所对应的组织 1：n的关系
     * @param staffId
     * @return
     */
    @Override
    public List<OrganizationInfoDo> selectOrganizationInfoByStaffId(String staffId) {
        SqlString sqlString = new SqlString();
        sqlString.add("SELECT * FROM organization_info WHERE");
        sqlString.add(" org_id= (SELECT org_id FROM staff_org_rel WHERE staff_id =? ) ");
        Object[] params = new Object[]{
                staffId
        };
        return jdbcSupportTemplate.selectList(sqlString.build(), params, OrganizationInfoDo.class);
    }
}
